package online.mjchow.fic.controller;

import com.alibaba.fastjson.JSONObject;
import com.xiaoleilu.hutool.http.HttpRequest;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by mjchow on 17-11-30.
 */
public class BaseController {


    public List<Integer> getIntArrayByStringArray(String[] array) {
        if(array.length > 0) {
            List<Integer> list = new ArrayList<>();
            for(String str: array) {
                list.add(Integer.valueOf(str));
            }
            return list;
        }
        return null;
    }

    public String getAllCity(double longitude, double latitude) {
        try {
            String res = HttpRequest.get("http://recode.ditu.aliyun.com/dist_query?l=" + latitude + "," + longitude).charset(Charset.forName("gbk")).execute().body();
            if (res != null) {
                JSONObject jsonObject = JSONObject.parseObject(res);
                String dist = jsonObject.getString("dist");
                if (dist != null) {
                    return dist;
                }
            }
        } catch (Exception e) {e.printStackTrace();}
        return "";
    }
}
